const assert = require('assert');
// const macObj = require('getmac');
const BasicController = require('../BasicController.js');

module.exports = class extends BasicController {
  constructor(ctx) {
    super(ctx);
    assert(think.isFunction(this.model), 'this.model must be a function');
    this.MODEL = this.ctx.state.ApiInfo.model;
    this.params = {
      model: this.MODEL,
      data: this.post()
    };
  }
  async checkTimeAction() {
    if (this.isCli) return this.fail(1000, 'deny');
    const params = this.params;
    const data = await this.model('notice').where({status: 1}).select();
    const updateData = {
      status: 0
    };
    data.forEach(element => {
      const s1 = (new Date()).getTime();
      const s2 = (new Date(element.deadline)).getTime();
      if (s2 - s1 < 0) {
        this.model(params.model).where({notice_id: element.id}).update(updateData);
      }
    });
  }
  async readOffAction() {
    const params = this.params;
    const data = await this.model(params.model).readOffAction(params);
    return this.success(data);
  }
  async readcountAction() {
    const params = this.params;
    const data = await this.model(params.model).readcountAction(params);
    return this.success(data);
  }
  async readdetailAction() {
    const params = this.params;
    const data = await this.model(params.model).readdetailAction(params);
    return this.success(data);
  }
};
/**
  *@api {post} /user_notice/user_notice/readOff /readOff
 * @apiName readOff
 * @apiGroup user_notice
 * @apiParam {String} notice_id 通知id
 * @apiParam {String} user_id 用户id
 * @apiVersion 1.0.0
 * @apiSuccessExample 请求成功demo:
 *     HTTP/1.1 200 OK
 *     {
 *       {
    "errno": 0,
    "errmsg": "ok",
    "data": 1
}
 *     }
 *
 *
 * @apiErrorExample 请求失败返回demo:
 *     HTTP/1.1 404 Not Found
 *     {
 *          "errno": 404,
          "errmsg": "请求路径错误",
          "data":
 *     }
 * @apiParamExample {delete} Request-Example:
                 {
                 }
*/
/**
  *@api {post} /user_notice/user_notice/readcount /readcount
 * @apiName rereadcountadOff
 * @apiGroup user_notice
 * @apiVersion 1.0.0
 * @apiSuccessExample 请求成功demo:
 *     HTTP/1.1 200 OK
 *     {
 *       {
    "errno": 0,
    "errmsg": "ok",
    "data": 1
}
 *     }
 *
 *
 * @apiErrorExample 请求失败返回demo:
 *     HTTP/1.1 404 Not Found
 *     {
 *          "errno": 404,
          "errmsg": "请求路径错误",
          "data":
 *     }
 * @apiParamExample {delete} Request-Example:
                 {
                   空
                 }
*/
/**
  *@api {post} /user_notice/user_notice/readdetail /readdetail
 * @apiName readdetail
 * @apiGroup user_notice
 * @apiParam {String} notice_id 通知id
 * @apiVersion 1.0.0
 * @apiSuccessExample 请求成功demo:
 *     HTTP/1.1 200 OK
 *     {
 *       {
    "errno": 0,
    "errmsg": "ok",
    "data": 1
}
 *     }
 *
 *
 * @apiErrorExample 请求失败返回demo:
 *     HTTP/1.1 404 Not Found
 *     {
 *          "errno": 404,
          "errmsg": "请求路径错误",
          "data":
 *     }
 * @apiParamExample {delete} Request-Example:
                 {
                   notice_id:***********
                 }
*/
